
//让一个普通类成为处理器，实现servet接口 或者继承HttpServet  成为处理器类

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;

@WebServlet("/user")
public class HelloWorldServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        // 业务逻辑处理
//        String username = "张三";
//        int age = 25;

        String username =  request.getParameter("username");
        String age = request.getParameter("age");

        // 将数据设置到request属性中
        request.setAttribute("name", username);
        request.setAttribute("age", age);
        request.setAttribute("users", Arrays.asList("李四", "王五"));

        // 转发到JSP页面
        RequestDispatcher dispatcher = request.getRequestDispatcher("/hello.jsp");
        dispatcher.forward(request, response);
    }
}
